<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改用户')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-wxuser-edit" th:object="${wxUser}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">账号：</label>
                <div class="col-sm-8">
                    <input name="account" th:field="*{account}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">密码：</label>
                <div class="col-sm-8">
                    <input name="password" th:field="*{password}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">昵称：</label>
                <div class="col-sm-8">
                    <input name="nickname" th:field="*{nickname}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">头像：</label>
                <div class="col-sm-8">
                    <input name="icon" th:field="*{icon}" class="form-control" type="text" readonly>
                    <div class="photo-add">
                        <input type="file" accept="image/*"
                               name="uploader-input"
                               class="uploader-file"
                               id="upload">
                    </div>
                    <div id="box"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">手机号：</label>
                <div class="col-sm-8">
                    <input name="phone" th:field="*{phone}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">邮箱：</label>
                <div class="col-sm-8">
                    <input name="mail" th:field="*{mail}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">手机识别码：</label>
                <div class="col-sm-8">
                    <input name="imei" th:field="*{imei}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/wxuser";
        $("#form-wxuser-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-wxuser-edit').serialize());
            }
        }

        $("input[name='addtime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='modifytime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        document.getElementById('upload').addEventListener('change', function (event) {
            var $file = event.currentTarget;
            var formData = new FormData();
            var file = $file.files;
            formData = new FormData();
            formData.append("file", file[0]);
            $.ajax({
                url: ctx + "common/upload",
                type: 'POST',
                dataType: 'json',
                data: formData,
                contentType: false,
                processData: false
            })
                .done(data => {
                    console.log(data);
                    $('#icon').val(data.url);
                    $('#box').append(`<div class="photo-item">
            <img class="item-image" width="100%" height="100%" src="${data.url}"/>
        </div>`);
                })
                .fail(data => {
                    console.log(data);
                });
        });
    </script>
</body>
</html>
